<!DOCTYPE html>
<html class="x-admin-sm">
<head>
    <meta charset="UTF-8">
    <title>宇成建筑</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <link rel="stylesheet" href="../statics/css/font.css">
    <link rel="stylesheet" href="../statics/plugins/layui/css/layui.css">
    <link rel="stylesheet" href="../statics/css/xadmin.css">
    <link rel="stylesheet" href="../statics/css/style.css">
</head>

<body class='labelAuto'>
<div class="x-nav">
        <span class="layui-breadcrumb">
            <a href="welcome.html">首页</a>
            <a href="javascript:;">人力资源管理</a>
            <a>
                <cite>日工值列表</cite></a>
        </span>
    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right"
       onclick="location.reload()" title="刷新">
        <i class="layui-icon layui-icon-refresh" style="line-height:30px"></i>
    </a>
</div>
<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-body search">
                    <form action="" class="layui-form livingList">
                        <div class="layui-form-item">
                            <div class="layui-inline">
                                <label class="layui-form-label">项目</label>
                                <div class="layui-input-block">
                                    <select name="city" lay-verify="required" id="project">
                                        <option value="null">-</option>
                                    </select>
                                </div>
                            </div>
                            <div class="layui-inline">
                                <label class="layui-form-label">工种</label>
                                <div class="layui-input-block">
                                    <select name="city" lay-verify="required" id="peopleType">
                                        <option value="null">-</option>
                                    </select>
                                </div>
                            </div>
                            <div class="layui-inline">
                                <label class="layui-form-label">搜索</label>
                                <div class="layui-input-block">
                                    <input type="search" autocomplete="off" placeholder="输入工人姓名/工号" class="layui-input"
                                           id="searchInput">
                                </div>
                            </div>
                            <div class="layui-inline">
                                <button class="layui-btn search" type="button" id='search'>
                                    <i class="iconfont layui-icon">&#xe615;</i>
                                </button>
                            </div>
                        </div>
                    </form>
                </div>
                <div class="layui-card-body tableCardBody">
                    <table class="layui-table" id="lists" lay-filter="test"></table>
                </div>
            </div>
        </div>
    </div>
</div>
</body>
<script src="../statics/plugins/layui/layui.js" charset="utf-8"></script>
<script src='../statics/plugins/jQuery-3.2.1/jquery-3.2.1.min.js'></script>
<script type="text/javascript" src="../statics/plugins/X-admin/xadmin.js"></script>
<script type="text/javascript" src="../statics/js/public.js?v=1129"></script>
<script type="text/html" id="toolbar">
    <div class="layui-inline">
        <button type="button" class='saves layui-btn' auth='editDayValue'>批量保存</button>
    </div>
</script>
<script type="text/javascript">
    layui.use(['form', 'layer', "table", "laydate"], function () {
        var table = layui.table;
        var form = layui.form;
        var laydate = layui.laydate;
        var layer = layui.layer;
        $('#project').empty().html(projectSelect());
        $('#peopleType').empty().html(professionSelect());
        form.render();
        //批量保存
        $('body').on('click', '.saves', function () {
            var data = [];
            for (var i = 0; i < $('table button.baocun').length; i++) {
                var list = {
                    employeeId: Number(),
                    dayValue: Number()
                }
                list.employeeId = Number($('table button.baocun').eq(i).data('id'));
                list.dayValue = Number($('table button.baocun').eq(i).parent().parent().prev().prev().find('input').val());
                data.push(list);
            }
            $.ajax({
                url: url + '/hrm/employee/batchEditDayValue',
                data: JSON.stringify({
                    data: data,
                    token: getToken()
                }),
                type: 'post',
                contentType: "application/json; charset=utf-8",
                success: function (r) {
                    if (r.code == 100000) {
                        tips('批量保存', r);
                        setTimeout(function () {
                            layer.closeAll();
                            table.reload('lists');
                        }, 1000)
                    } else {
                        tips('批量保存', r);
                    }
                }
            })
        })
        // 异步数据加载
        var lists = table.render({
            elem: '#lists', //绑定DOM元素
            id: 'lists', //table的id
            title: '日工值列表',
            height: 'full-150',
            contentType: "application/json; charset=utf-8",
            url: url + '/hrm/employee/dayValueLists', //数据接口地址
            request: {
                pageName: 'page', //页码的参数名称，默认：page
                limitName: 'length' //每页数据量的参数名，默认：limit
            },
            method: 'POST',
            parseData: function (res) {
                return {
                    "code": res.code, //解析接口状态
                    "data": res.data.data,
                    "msg": res.msg,
                    "count": res.data.count
                };
            },
            where: {
                projectId: 0,
                professionId: '',
                search: "",
                token: getToken()
            },
            toolbar: '#toolbar',
            defaultToolbar: ['filter'],
            page: true, //开启分页
            limit: 10, //默认每页记录条数
            limits: [10, 20, 50], //每页记录条数可选数量
            cols: [
                [ //表头
                    {field: '', title: '编号', type: 'numbers', width: '8%'},
                    {field: 'jobNumber', title: '工号', width: '8%'},
                    {field: 'name', title: '姓名', width: '8%'},
                    {field: 'projectName', title: '项目名称', width: '13%'},
                    {field: 'professionName', title: '工种', width: '10%'},
                    {
                        field: 'status', title: '工作状态', templet: function (d) {
                            return `${d.status == 1 ? "在岗" : d.status == 3 ? "请假" : d.status == 4 ? "离职" : ""}`
                        }
                    },
                    {field: 'attendance', title: '考勤时长'},
                    {
                        field: 'dayValue', title: '日工值', templet(d) {
                            return html = `
                            <input type='number' value='${d.dayValue}' onkeyup='limitInput_1(this)' class="layui-input" min="0">
                        `
                        }
                    },
                    {
                        field: 'null', title: '考勤工资', templet(d) {
                            return Number(d.attendance)*Number(d.dayValue?d.dayValue:0);
                        }
                    },
                    {
                        field: '', title: '操作', templet: function (d) {
                            return `<button class='baocun layui-btn' lay-event='baocun' data-id=${d.id} auth='editDayValue'>保存</button>`
                        }
                    }
                ]
            ],
            response: {
                statusName: 'code', //数据状态的字段名称，默认：code
                statusCode: 100000, //成功的状态码，默认：0
                msgName: 'msg', //状态信息的字段名称，默认：msg
                countName: 'count', //数据总数的字段名称，默认：count
                dataName: 'data' //数据列表的字段名称，默认：data
            },
            done:function(){
                permission();
            }
        });

        table.on('tool(test)', function (data) {
            if (data.event == 'baocun') {
                var dayValue = $(this).parent().parent().prev().prev().find('input').val();
                if (dayValue < 0) {
                    layui.use('layer', function () {
                        var layer = layui.layer;
                        layer.open({
                            type: 1,
                            title: "保存日工值",
                            content: `<p class='one_p'>日工值不能小于0!</p>`,
                            btn: ['关闭'],
                            skin: 'my-skin'
                        })
                    });
                    return;
                } else {
                    $.ajax({
                        url: url + '/hrm/employee/batchEditDayValue',
                        data: JSON.stringify({
                            data: [{
                                employeeId: data.data.id,
                                dayValue: dayValue,
                            }],
                            token: getToken()
                        }),
                        type: 'post',
                        contentType: "application/json; charset=utf-8",
                        success: function (r) {
                            if (r.code == 100000) {
                                tips('批量保存', r);
                                setTimeout(function () {
                                    layer.closeAll();
                                    table.reload('lists');
                                }, 1000)
                            } else {
                                tips('批量保存', r);
                            }
                        }
                    })
                }
            }
        })
        $('body').on('change', 'table tbody input[type="text"]', function () {
            var value = $(this).val();
            var attendance = $(this).parent().prev().html();
            $(this).parent().next().html(Number(value) * Number(attendance));
        })

        //搜索
        $('body').on('click', 'button#search', function () {
            var projectId = $('#project option:selected').val();
            var professionId = $('#peopleType option:selected').val();
            table.reload('lists', {
                page: {
                    curr: 1 //重新从第 1 页开始
                },
                where: {
                    projectId: Number(projectId),
                    professionId: Number(professionId),
                    search: $('input#searchInput').val(),
                    token: getToken()
                }
            })
        })
    });
</script>

</html>